package com.student.liu.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 服务类方法拦截器，用于实现AOP
 */
@Slf4j
@Component
public class ServiceMethodInterceptor implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {

        Method method = invocation.getMethod();     //通过反射获取到当前执行的方法
        log.trace("增加的前置代码...方法名称：" + method.getName());

        Object result = invocation.proceed();   //相当于执行原本的方法，并获取返回的结果

        log.trace("增加的后置代码..." + result);
        return result;
    }

}
